const Router = require('koa-router')
const router = new Router()

var fs = require("fs");

router.get('/readFileSync',  async (ctx, next) => {

    const filename  = "./public/data/" + "test.txt"
    try{
        let data = fs.readFileSync(filename, 'utf-8')
        ctx.body =
        {
            status: 'success',
            filename: filename,
            fileData: data //JSON.stringify(data)
        }
    }
    catch(err){
        ctx.body =
        {
            status: 'success',
            filename: filename,
            fileData: err //JSON.stringify(data)
        }
    }

    await next()
})

module.exports = router;
